home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / Text / EnToutesLettres / ETL.DevDoc / FrenchCode.c < prev    next >
C/C++ Source or Header  |  1991-11-29  |  3KB  |  158 lines

  1. #include <SetUpA4.h>
  2.  
  3. static    char unites[10][8] = { "zéro ","un ","deux ","trois ","quatre ","cinq ","six ","sept ","huit ","neuf " }    ;
  4. static    char dizaines[10][14] = { "","dix ","vingt ","trente ","quarante ","cinquante ","soixante ","septante ","quatre-vingt","nonante " }    ;
  5. static     char multiples[4][9] = { "cent","mille","million" ,"milliard"}    ;
  6. static     char special[10][10] = { "et ","onze ","douze ","treize ","quatorze ","quinze ","seize ","dix-sept ","dix-huit ","dix-neuf "}    ;
  7.  
  8. char    *strcpy(char *s1,char *s2)    ;
  9. char    *strcat(char *s1,char *s2)    ;
  10. void    reverse(char *s)    ;
  11. short    strlen(char *s)    ;
  12. short    french(char *temp,char *tmpresult,short n)    ;
  13.  
  14. pascal void main(char *text,char *result)
  15. {
  16.     char    thestring[20],temp[4],tmpresult[256];
  17.     short    i,j,l,res        ;
  18.     short    plurial            ;
  19.     
  20.         RememberA0()        ;
  21.         SetUpA4()            ;
  22.         text[12] = 0        ;    /* max =  999 999 999 999 */
  23.         result[0] = '\0'    ;    
  24.         strcpy(thestring,text)    ;
  25.         if( strlen(thestring) != 0 )
  26.         {
  27.             while (thestring[0] == '0')
  28.                 for (i=0;thestring[i]!=0;thestring[i]=thestring[i+1],i++)    ;
  29.             plurial = 0 ;
  30.             if ( (l = strlen(thestring)) )
  31.             {
  32.                 reverse(thestring)    ;
  33.                 if (l < 12)
  34.                 {
  35.                     for ( i=l ; i<12 ; i++ )
  36.                         thestring[i] = '0'    ;
  37.                     thestring[12] = 0    ;
  38.                 }
  39.                 for ( i=3 ; i>=0 ; i--)
  40.                 {
  41.                     for ( j=3*i ; j<3*(i+1) ; j++)
  42.                         temp[j-3*i] = thestring[j]    ;
  43.                     temp[3] = 0         ;
  44.                     tmpresult[0] = 0    ;
  45.                     res = french(temp,tmpresult,i)    ;
  46.                     if ( (res > 1) || ((res == 1) && (i != 0)) )
  47.                         plurial = 1    ;
  48.                     strcat(result,tmpresult)        ;
  49.                 }
  50.             }
  51.             else
  52.                 strcpy(result,unites[0])    ;
  53.         }
  54.         RestoreA4()    ;
  55. }    
  56.  
  57. short french(char *temp,char *tmpresult,short n)
  58. {
  59.     register int res,x,y,z;
  60.  
  61.         reverse(temp);
  62.         x = temp[0]-'0'    ;
  63.         y = temp[1]-'0'    ;
  64.         z = temp[2]-'0'    ;
  65.         res = ((x*10)+y)*10+z;
  66.         if(res!=0)
  67.         {
  68.             if(x)
  69.             {
  70.                 if(x>1)
  71.                     strcpy(tmpresult,unites[x]);
  72.                 strcat(tmpresult,multiples[0]);
  73.                 if(x>1)
  74.                     if((n==0)&&(y==0)&&(z==0))
  75.                         strcat(tmpresult,"s");
  76.                 strcat(tmpresult," ");
  77.             }
  78.             if(y>1)
  79.             {
  80.                 strcat(tmpresult,dizaines[y]);
  81.                 if(y==8)
  82.                     if((z==0)&&(n==0))
  83.                         strcat(tmpresult,"s ");
  84.                     else
  85.                         strcat(tmpresult," ");
  86.             }
  87.             if(z)
  88.                 if(y==1)
  89.                     strcat(tmpresult,special[z]);
  90.                 else
  91.                 {
  92.                     if((z==1)&&(y!=0)&&(y!=8))
  93.                         strcat(tmpresult,special[0]);
  94.                     if((z!=1)||(n!=1)||(x!=0)||(y!=0))
  95.                         strcat(tmpresult,unites[z]);
  96.                 }
  97.             else
  98.                 if(y==1)
  99.                     strcat(tmpresult,dizaines[1]);
  100.             if (res && n)
  101.                 strcat(tmpresult,multiples[n]);
  102.             if ((res>1) &&(n>1))
  103.                 strcat(tmpresult,"s");
  104.             if (res &&(n>0))
  105.                 strcat(tmpresult," ");
  106.         }
  107. }
  108.  
  109. char * strcpy(char *s1,char *s2)
  110. {
  111.     asm {
  112.         movea.l    s1,a0        ;  A0 = s1
  113.         movea.l    s2,a1        ;  A1 = s2
  114.         move.l    a0,d0            ;  D0.L = result
  115. @1        move.b    (a1)+,(a0)+
  116.         bne.s    @1
  117.     }
  118. }
  119.  
  120.  
  121. char *strcat(char *s1,char *s2)
  122. {
  123.     asm {
  124.         movea.l    s1,a0        ;  A0 = s1
  125.         movea.l    s2,a1        ;  A1 = s2
  126.         move.l    a0,d0            ;  D0.L = result
  127. @1        tst.b    (a0)+
  128.         bne.s    @1
  129.         subq.l    #1,a0
  130. @2        move.b    (a1)+,(a0)+
  131.         bne.s    @2
  132.     }
  133. }
  134.  
  135. short strlen(char *s)
  136. {
  137.     asm {
  138.         moveq    #-1,d0            ;  D0.L = result
  139.         movea.l    s,a0        ;  A0 = s
  140. @1        addq.l    #1,d0
  141.         tst.b    (a0)+
  142.         bne.s    @1
  143.     }
  144. }
  145.  
  146. void reverse(char *s)
  147. {
  148.     register short        i,j        ;
  149.     register char        c        ;
  150.         
  151.         for(i=0,j=strlen(s)-1;i<j;i++,j--)
  152.         {
  153.             c = s[j]            ;
  154.             s[j] = s[i]            ;
  155.             s[i] = c            ;
  156.         }
  157. }
  158.